#include<iostream>
#include<vector>
#include<map>
using namespace std;


typedef struct TreeNode {
	map<int, TreeNode*> nodechild;
	int using_time;
}*node;


void insert(vector<int> ans, int point, TreeNode* node) {
	if (point == ans.size())return;
	if (node->nodechild.count(ans[point]) == 0) {
		TreeNode* temp = new TreeNode;
		node->nodechild.insert(pair<int, TreeNode*>(ans[point], temp));
		temp->using_time = 1;
	}
	else {
		node->nodechild[ans[point]]->using_time++;
	}
	insert(ans, point + 1, node->nodechild[ans[point]]);

}

int find(vector<int> result, int point, TreeNode* node) {
	if (point == result.size())return node == nullptr ? 0 : node->using_time;
	if (point < result.size())return node->nodechild[result[point]] == nullptr ? 0 : find(result, point + 1, node->nodechild[result[point]]);
}

int main() {
	int n, m, k, tempsize;
	cin >> n >> m >> k;
	TreeNode* node = new TreeNode;
	while (n--) {
		vector<int> tempA;
		cin >> tempsize;
		int ans, len;
		cin >> len;
		for (int i = 1; i < tempsize; i++) {
			cin >> ans;
			tempA.push_back(ans - len);
			len = ans;
		}
		insert(tempA, 0, node);
	}
	while (m--) {
		vector<int> tempB;
		cin >> tempsize;
		int ans, len;
		cin >> len;
		for (int i = 1; i < tempsize; i++) {
			cin >> ans;
			tempB.push_back(ans - len);
			len = ans;
		}
		cout << find(tempB, 0, node) << endl;
	}
}